package com.wu.Service.ServiceImpl;

import com.wu.DO.studentDO;
import com.wu.Dao.StudentMapper;
import com.wu.Service.StudentService;

import com.wu.common.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by admin on 2018/11/19.
 */
@Component
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public ServerResponse<studentDO> login(String username, String password) {
        int usercheck = studentMapper.checkUserName(username);
        if (usercheck == 0) {
            return ServerResponse.createByErrorMessage("用户名不存在");
        }
     //   String MD5password = MD5Util.MD5EncodeUtf8(password);
        studentDO student = studentMapper.login(username, password);
        if (student == null) {
            return ServerResponse.createByErrorMessage("用户密码不正确");
        }
        return ServerResponse.createBySuccess("登录成功",student);
    }

    @Override
    public ServerResponse<String> addStudent(Integer studentId,String username,String password,String sname, String studentClass, String sex, String phoneNumber, String email, String identityNumber) {
        int count= studentMapper.addStudent(studentId,username,password,sname,studentClass,sex,phoneNumber,
                email,identityNumber);
        if (count==0) {
            return ServerResponse.createByErrorMessage("添加学生信息失败");
        }
        return ServerResponse.createBySuccess("成功添加学生信息");
    }

//    @Override
//    public ServerResponse<String> changeStuPwd(Integer studentId, String password,String identityNumber){
//        int count = studentMapper.changeStuPwd(studentId,password,identityNumber);
//     if (student.identityNumber==identityNumber){
//
//     }
//
//        else{
//            return ServerResponse.createByErrorMessage("修改学生密码失败");
//
//        }
//    }
}
